package command.receiver;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.List;
import java.util.Map.Entry;

import pojo.Protocol;
import util.ProtocolJSONConverter;
import command.BaseReceiver;

public class ReturnToUserReceiver extends BaseReceiver {
	
	private OutputStream out;

	public ReturnToUserReceiver(OutputStream out, Protocol protocol) {
		super(null, protocol);
		this.out = out;
	}

	@Override
	public Entry<Integer, List<Object>> action() throws IOException {
		BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
		writer.write(ProtocolJSONConverter.toJSON(protocol) + "\n");
		writer.flush();
		return null;
	}

}
